home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
5_2.lha
/
5_2
/
5_2b2.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
530b
|
33 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ find a word within the tree
include <tree.h>
include <string.h>
node *tree:: findnode(char *s)
tnode *cur = head;
for (;;)
{
if (!cur)
return 0;
int cmp = strcmp(s, cur->tword);
// check the left subtree
if (cmp < 0)
cur = cur->left;
// check the right subtree
else if (cmp > 0)
cur = cur->right;
// equal, found it
else /* if (cmp == 0) */
return cur;
}